********************************************************************************
*Project:  	Swiss Trade During the Covid-19 Pandemic: An Early Appraisal	
*Authors:	KB, SL, VP, PW										
*This File: Clean Trade Data
*Version: 	vFinal						
*Date: 		2020-09-01					
********************************************************************************

********************************************************************************
*1. Import Data
********************************************************************************

*Import Trade Data 2002-2011
import delimited "${root}\data\FCA_Weekly_Data\2002_bis_2011_DATEN_KW_ab_EDB.csv",	///   	2002_2011_DATENLIEFERUNG_DEF.csv
delimiter(";") asdouble clear 

rename stat_jahr jahr
drop if konjunktur == "N"
collapse (sum) kg chf, by(vk jahr kw wa land konjunktur aktualisierung)
duplicates report vk jahr kw wa land 

saveold "${root}\temp\raw_2002_2011.dta", replace version(13)

*Import Trade Data 2012-2019
import delimited "${root}\data\FCA_Weekly_Data\2012_bis_2019_DATEN_KW_ab_EDB.csv",	///		2012_2018_DATENLIEFERUNG_DEF.csv
delimiter(";") asdouble clear 

rename stat_jahr jahr
drop if konjunktur == "N"
collapse (sum) kg chf, by(vk jahr kw wa land konjunktur aktualisierung)
duplicates report vk jahr kw wa land 

saveold "${root}\temp\raw_2012_2019.dta", replace version(13)

*Import Trade Data 2020
import delimited "${root}\data\FCA_Weekly_Data\20200818_DATEN_KW.csv",		///				20200609_DATENLIEFERUNG_LJ.csv
delimiter(";") asdouble clear 

rename stat_jahr jahr
drop if konjunktur == "N"
collapse (sum) kg chf, by(vk jahr kw wa land konjunktur aktualisierung)

duplicates tag vk jahr kw wa land, gen(dup1)
tab dup1
drop dup1

saveold "${root}\temp\raw_2020.dta", replace version(13)

*Append years and merge codes
clear

append using "${root}\temp\raw_2002_2011.dta"
append using "${root}\temp\raw_2012_2019.dta"
append using "${root}\temp\raw_2020.dta"

drop aktualisierung

rename vk handel_typ
rename kw woche
rename wa waren_art_id
rename land land_id
rename kg handel_kg
rename chf handel_chf

*Merge Länder Labels
merge m:1 land_id using "${root}\temp\codes_land.dta"
drop if _merge==2 /*Schweiz*/
replace land_iso2="zzna" if _merge==1
replace land_str="zzna: UNKNOWN" if _merge==1  
rename _merge merge_land

*Merge Waren Labels
tostring waren_art_id, replace
replace waren_art_id="0"+waren_art_id if index(waren_art_id, ".")==2

*No Labels for 13.1, 13.2, 14.1, 14.2 --> change to add up to 13/14
clonevar wid=waren_art_id
replace waren_art_id="13" if inlist(waren_art_id, "13.1", "13.2")
replace waren_art_id="14" if inlist(waren_art_id, "14.1", "14.2")

bysort handel_typ jahr woche land_id waren_art_id: egen double total_chf=total(handel_chf)
bysort handel_typ jahr woche land_id waren_art_id: egen double total_kg=total(handel_kg)

replace handel_chf=total_chf if handel_chf!=total_chf & inlist(waren_art_id, "13", "14")
replace handel_chf=total_chf if handel_chf!=total_chf 

replace handel_kg=total_kg if handel_kg!=total_kg & inlist(waren_art_id, "13", "14")
replace handel_kg=total_kg if handel_kg!=total_kg

duplicates tag jahr woche handel_typ waren_art_id land_id total_chf total_kg, gen(dup)
drop if dup==1 & (wid=="13.2" | wid=="14.2")
drop dup wid total_chf total_kg

merge m:1 waren_art_id using "${root}\temp\codes_warenart.dta"
tab _merge
drop if _merge==2
rename _merge merge_waren

sort jahr woche handel_typ waren_art_id land_id

*ADD KW53 in 2005, 2010, 2016 TO KW52 (CHECK WITH EVZ WHY KW53 IN THESE YEARS)
clonevar wo=woche

replace woche=52 if woche==53 & inlist(jahr, 2005, 2010, 2016)

bysort handel_typ jahr woche land_id waren_art_id: egen double total_chf=total(handel_chf)
bysort handel_typ jahr woche land_id waren_art_id: egen double total_kg=total(handel_kg)

replace handel_chf=total_chf if handel_chf!=total_chf & 						///
inlist(jahr, 2005, 2010, 2016) & woche==52
replace handel_chf=total_chf if handel_chf!=total_chf 

replace handel_kg=total_kg if handel_kg!=total_kg & 							///
inlist(jahr, 2005, 2010, 2016) & woche==52
replace handel_kg=total_kg if handel_kg!=total_kg 

duplicates tag jahr woche handel_typ waren_art_id land_id total_chf total_kg, gen(dup)
drop if dup==1 & wo==53
drop dup wo total_chf total_kg

duplicates report jahr woche handel_typ waren_art_id land_id

sort jahr woche handel_typ waren_art_id land_id

order jahr woche handel_typ waren_art_id waren_art_str land_id land_str land_iso2 ///
handel_chf handel_kg merge_land merge_waren

compress
saveold "${root}\temp\trade_2002_2020_basic_temp.dta", replace version(13)

********************************************************************************
*2. Generate Additional Variables
********************************************************************************

use "${root}\temp\trade_2002_2020_basic_temp.dta", replace

*Eliminiere Kategorie 13 (Edelmetalle) und 14 (Kunst und Antiquitäten)
drop if inlist(waren_art_id, "13", "14")

tab konjunktur, missing
drop konjunktur /*No variation*/

*Volumen in Mia / Tonnen
gen handel_chf_mio=handel_chf/(1000*1000)
gen handel_chf_mia=handel_chf/(1000*1000*1000)
gen handel_tonnen=handel_kg/(1000)

*Fortlaufende Wochennummer
preserve
keep jahr woche 
duplicates drop jahr woche, force
sort jahr woche
gen woche_seq=_n
saveold "${root}\temp\woche53_seq.dta", replace version(13)

drop if woche==53
drop woche_seq
sort jahr woche
gen woche_seq=_n
save "${root}\temp\woche52_seq.dta", replace
restore

merge m:1 jahr woche using "${root}\temp\woche53_seq.dta"
drop _merge
rename woche_seq woche_seq53

merge m:1 jahr woche using "${root}\temp\woche52_seq.dta"
drop _merge
rename woche_seq woche_seq52


*Variablen für aggregierte Warenarten
*************************************

*KAT12: Hauptkategorien gemäss FCA
split waren_art_id, parse(".")

destring waren_art_id1, gen(waren_art_kat12)
drop waren_art_id1 waren_art_id2

label define kat12																///
1 "(1) Land- & Forstwirtschaftliche Produkte"									///
2 "(2) Energieträger"															///
3 "(3) Textilien"																///
4 "(4) Papierwaren & grafische Erzeugnisse"										///
5 "(5) Leder, Kautschuk, Kunststoffe"											///
6 "(6) Produkte d. Chemischen/Pharmazeutischen Industrie"						///
7 "(7) Erden / Steine"															///
8 "(8) Metalle"																	///
9 "(9) Maschinen, Elektronik, Apparate"											///
10 "(10) Fahrzeuge"																///
11 "(11) Präzisionsinstrumente, Uhren, Schmuck"									///
12 "(12) Verschiedenes (Möbel, Sportgeräte, Instrumente usw.)"
label values waren_art_kat12 kat12

*KAT 6: Zusammengefasste Hauptkategorien 															
gen waren_art_kat6=.

replace waren_art_kat6=610 if inlist(waren_art_kat12, 1) 
replace waren_art_kat6=620 if inlist(waren_art_kat12, 2)
replace waren_art_kat6=630 if inlist(waren_art_kat12, 3, 4, 12) | inlist(waren_art_id, "11.3")
replace waren_art_kat6=640 if inlist(waren_art_kat12, 5, 7)
replace waren_art_kat6=650 if inlist(waren_art_kat12, 6)
replace waren_art_kat6=660 if inlist(waren_art_kat12, 8, 9, 10) | inlist(waren_art_id, "11.1", "11.2")

label define kat6																///
610 "(610) Land- & Forstwirtschaftliche Produkte"								///
620 "(620) Energieträger"														///
630 "(630) Leichtindustrie: Textilien, Papierwaren, Schmuck, Verschiedenes"		///
640 "(640) Rohstoffe (exkl. Metall): Leder, Kunstoffe, Kautschuk, Steine"		///
650 "(650) Chemische/Pharmazeutische Produkte"									///
660 "(660) Metall & Industrie: Metall, Maschinen, Elektronik, Fahrzeuge, Präzisionsinstrumente"						
label values waren_art_kat6 kat6

*KAT 5: Zusammengefasste Hauptkategorien
gen waren_art_kat5=.

replace waren_art_kat5=510 if inlist(waren_art_kat12, 1)
replace waren_art_kat5=520 if inlist(waren_art_kat12, 2)
replace waren_art_kat5=530 if inlist(waren_art_kat12, 3, 4, 5, 7, 12) | inlist(waren_art_id, "11.3")
replace waren_art_kat5=540 if inlist(waren_art_kat12, 6)
replace waren_art_kat5=550 if inlist(waren_art_kat12, 8, 9, 10) | inlist(waren_art_id, "11.1", "11.2")
label define kat5																///
510 "(510) Land- & Forstwirtschaftliche Produkte"								///
520 "(520) Energieträger"														///
530 "(530) Leichtindustrie & Rohstoffe (exkl. Metall): Textilien, Papierwaren, Schmuck, Leder, Steine"	///					
540 "(550) Chemischen/Pharmazeutische Produkte"									///
550 "(550) Metall & Industrie: Metall, Maschinen, Elektronik, Fahrzeuge, Präzisionsinstrumente"																	
label values waren_art_kat5 kat5

*KAT 4: Zusammengefasste Hauptkategorien
gen waren_art_kat4=.

replace waren_art_kat4=410 if inlist(waren_art_kat12, 1, 3, 4, 5, 7, 12) | inlist(waren_art_id, "11.3")
replace waren_art_kat4=420 if inlist(waren_art_kat12, 2)
replace waren_art_kat4=430 if inlist(waren_art_kat12, 6)
replace waren_art_kat4=440 if inlist(waren_art_kat12, 8, 9, 10) | inlist(waren_art_id, "11.1", "11.2")

label define kat4																///
410 "(410) Verschiedenes"														///
420 "(420) Energieträger"														///
430 "(430) Chemischen/Pharmazeutische Produkte"									///
440 "(440) Metall & Industrie: Metall, Maschinen, Elektronik, Fahrzeuge, Präzisionsinstrumente"													
label values waren_art_kat4 kat4

*KAT 3: Zusammengefasste Hauptkategorien
gen waren_art_kat3=.

replace waren_art_kat3=310 if inlist(waren_art_kat12, 1, 2, 3, 4, 5, 7, 12) | inlist(waren_art_id, "11.3")
replace waren_art_kat3=320 if inlist(waren_art_kat12, 6)
replace waren_art_kat3=330 if inlist(waren_art_kat12, 8, 9, 10) | inlist(waren_art_id, "11.1", "11.2")

label define kat3																///
310 "(310) Total excl. Chemie sowie Metall & Industrie"							///
320 "(320) Chemischen/Pharmazeutische Produkte"									///
330 "(330) Metall & Industrie: Metall, Maschinen, Elektronik, Fahrzeuge, Präzisionsinstrumente"													
label values waren_art_kat3 kat3

*KAT 2: Zusammengefasste Hauptkategorien
gen waren_art_kat2=.

replace waren_art_kat2=210 if inlist(waren_art_kat12, 1, 3, 4, 12, 9, 10, 11, 5, 7, 8, 2)
replace waren_art_kat2=220 if inlist(waren_art_kat12, 6)

label define kat2																///
210 "(210) Total excl. Chemie/Pharmazie"										///
220 "(220) Chemischen/Pharmazeutische Produkte"													
label values waren_art_kat2 kat2


*Aggregierte Statistiken
************************
*Merge Land Group Indicators from UNCTAD
merge m:1 land_iso2 using "${root}\temp\UNCTAD_country_groups.dta", keepusing(land_region7 EU2020 Eurozone EU_EFTA_2020) 
drop if _merge==2
rename _merge merge_land_gruppen

replace land_region7="no merge" if merge_land_gruppen==1

foreach var in EU2020 Eurozone EU_EFTA_2020 {
	replace `var'=0 if merge_land_gruppen==1
}

rename EU2020 land_EU
rename Eurozone land_EURO
rename EU_EFTA_2020 land_EEA

*Aggregierte Statistiken: Total
preserve
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ)								

gen waren_art_id="9999" 
gen waren_art_str="total" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=99
saveold "${root}\temp\total_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT12
preserve 
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ waren_art_kat12)								

gen waren_art_id="8012" 
gen waren_art_str="12 Kategorien (FCA)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=51
saveold "${root}\temp\kat12_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT6
preserve 
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ waren_art_kat6)								

gen waren_art_id="8006" 
gen waren_art_str="6 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=56
saveold "${root}\temp\kat6_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT5
preserve 
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ waren_art_kat5)								

gen waren_art_id="8005" 
gen waren_art_str="5 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=55
saveold "${root}\temp\kat5_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT4
preserve 
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ waren_art_kat4)								

gen waren_art_id="8004" 
gen waren_art_str="4 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=54
saveold "${root}\temp\kat4_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT3
preserve 
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ waren_art_kat3)								

gen waren_art_id="8003" 
gen waren_art_str="3 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=53
saveold "${root}\temp\kat3_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Warenart KAT2
preserve 
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ waren_art_kat2)								

gen waren_art_id="8002" 
gen waren_art_str="2 Kategorien (own)" 
gen land_id=9999
gen land_str="world"
gen land_iso2="world"
gen SAMPLE=52
saveold "${root}\temp\kat2_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken: Nach Land
preserve
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ land_id land_str land_iso2)								

gen waren_art_id="9999" 
gen waren_art_str="total" 
gen SAMPLE=21
saveold "${root}\temp\country_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken nach Region (Kontinent)
preserve
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ land_region7)								

gen waren_art_id="9999" 
gen waren_art_str="total" 
gen land_id=8888
gen land_str=land_region7
gen land_iso2=land_region7
gen SAMPLE=22
saveold "${root}\temp\region7_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken nach EU2020
preserve
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ land_EU)								

gen waren_art_id="9999" 
gen waren_art_str="total" 
gen land_id=7771
gen land_str="EU2020" if land_EU==1
replace land_str="NOT EU" if land_EU==0
gen land_iso2="EU2020" if land_EU==1
replace land_iso2="NOT EU" if land_EU==0
gen SAMPLE=31
saveold "${root}\temp\EU_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken nach EU+EFTA_2020 (European Economic Area)
preserve
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ land_EEA)								
gen waren_art_id="9999" 
gen waren_art_str="total" 
gen land_id=7772
gen land_str="EEA" if land_EEA==1
replace land_str="NOT EEA" if land_EEA==0
gen land_iso2="EEA" if land_EEA==1
replace land_iso2="NOT EEA" if land_EEA==0
gen SAMPLE=32
saveold "${root}\temp\EEA_trade_temp.dta", replace version(13)
restore 

*Aggregierte Statistiken nach Eurozone
preserve
collapse (sum) handel_chf_mio handel_chf_mia handel_tonnen, 					///
by(jahr woche woche_seq53 woche_seq52 handel_typ land_EURO)								

gen waren_art_id="9999" 
gen waren_art_str="total"
gen land_id=7773
gen land_str="Eurozone" if land_EURO==1
replace land_str="NOT Eurozone" if land_EURO==0
gen land_iso2="Eurozone" if land_EURO==1
replace land_iso2="NOT Eurozone" if land_EURO==0
gen SAMPLE=33
saveold "${root}\temp\EURO_trade_temp.dta", replace 
restore 

*Append aggregierte Statistiken
gen SAMPLE=1
append using "${root}\temp\total_trade_temp.dta"
append using "${root}\temp\country_trade_temp.dta"
append using "${root}\temp\region7_trade_temp.dta"
append using "${root}\temp\EU_trade_temp.dta"
append using "${root}\temp\EEA_trade_temp.dta"
append using "${root}\temp\EURO_trade_temp.dta"
append using "${root}\temp\kat12_trade_temp.dta"
append using "${root}\temp\kat6_trade_temp.dta"
append using "${root}\temp\kat5_trade_temp.dta"
append using "${root}\temp\kat4_trade_temp.dta"
append using "${root}\temp\kat3_trade_temp.dta"
append using "${root}\temp\kat2_trade_temp.dta"

label define smple																///
1 "(1) Rohdaten -- Woche, Warenart, Land"										/// 
21 "(21) Ländertotal -- Woche, Land"											///
22 "(22) Kontinenttotal -- Woche, Kontinent"									///
31 "(31) EU-Total (inkl. GB) -- Woche, EU vs. !EU"								///
32 "(32) EU+EFTA-Total (inkl. GB) -- Woche, EU/EFTA vs. !EU/EFTA"				///
33 "(33) Eurozone-Total -- Woche, Eurozone vs. !Eurozone"						///
51 "(51) Kat. 12: Warenart-Total -- Woche, Handelvolumen, Kat12"				///
52 "(52) Kat. 2: Warenart-Total -- Woche, Handelvolumen, Kat2"					///
53 "(53) Kat. 3: Warenart-Total -- Woche, Handelvolumen, Kat3"					///
54 "(54) Kat. 4: Warenart-Total -- Woche, Handelvolumen, Kat4"					///
55 "(55) Kat. 5: Warenart-Total -- Woche, Handelvolumen, Kat5"					///
56 "(56) Kat. 6: Warenart-Total -- Woche, Handelvolumen, Kat6"					///
99 "(99) Welt-Total -- Woche, Handelsvolumen"
label values SAMPLE smple

*Generiere Datumsvariable
*siehe Forumsbeitrag von https://www.stata.com/statalist/archive/2012-08/msg00053.html
gen jan1 = dow(mdy(1,1,jahr))
local wanted = 4
gen weeklydates = cond(jan1 <= `wanted', 1 -  jan1 + `wanted', 8 - jan1 + `wanted')
replace weeklydates = weeklydates + (woche - 1) * 7
replace weeklydates = . if weeklydates > doy(mdy(12, 31, jahr))
gen datum_do = mdy(1,1, jahr) + weeklydates - 1
format datum_do %tdCCYY
gen datum_mo = datum_do-3
format datum_mo %td
gen datum_di = datum_do-2
format datum_di %td
gen datum_mi = datum_do-1
format datum_mi %td
gen datum_fr = datum_do+1
format datum_fr %td
gen datum_sa = datum_do+2
format datum_sa %td
gen datum_so = datum_do+3
format datum_so %td

drop jan1 weeklydates 

foreach var of varlist _all {
	label var `var' ""
}

sort SAMPLE jahr woche handel_typ waren_art_id land_id  land_str

order SAMPLE jahr woche woche_seq53 woche_seq52									///
handel_typ waren_art_id waren_art_str land_id land_str land_iso2 land_region7	///
handel_chf handel_chf_mio handel_chf_mia handel_kg handel_tonnen 				///
datum_mo datum_di datum_mi datum_do datum_fr datum_sa datum_so					///
land_EU land_EURO land_EEA	waren_art_kat*										///
merge_land merge_waren merge_land_gruppen 									

compress
saveold "${root}\temp\trade_2002_2020_analysis_temp.dta", replace version(13)

*wide format
use "${root}\temp\trade_2002_2020_analysis_temp.dta", clear


gen var_name=""
replace var_name="land_iso2" if SAMPLE==1
replace var_name="land_iso2" if SAMPLE==21
replace var_name="land_region7" if SAMPLE==22
replace var_name="land_EU" if SAMPLE==31
replace var_name="land_EEA" if SAMPLE==32
replace var_name="land_EURO" if SAMPLE==33
replace var_name="waren_art_kat12" if SAMPLE==51
replace var_name="waren_art_kat2" if SAMPLE==52
replace var_name="waren_art_kat3" if SAMPLE==53
replace var_name="waren_art_kat4" if SAMPLE==54
replace var_name="waren_art_kat5" if SAMPLE==55
replace var_name="waren_art_kat6" if SAMPLE==56
replace var_name="land_iso2" if SAMPLE==99


levelsof SAMPLE, local(sample)
foreach num of local sample {
	
	preserve 
	keep if SAMPLE==`num'
	
	levelsof var_name, local(add_var) clean
	di in red "`add_var'"
	
	drop handel_chf handel_kg
	reshape wide handel_chf_mio handel_chf_mia handel_tonnen,					///
	i(SAMPLE jahr woche woche_seq53 waren_art_id land_id `add_var')				///
	j(handel_typ) string

	rename handel_chf_mioE export_chf_mio
	rename handel_chf_miaE export_chf_mia
	rename handel_tonnenE export_tonnen

	rename handel_chf_mioI import_chf_mio
	rename handel_chf_miaI import_chf_mia
	rename handel_tonnenI import_tonnen

	foreach v in  chf_mio chf_mia  tonnen {
		foreach t in export import {
			replace `t'_`v'=0 if `t'_`v'==.
			format `t'_`v' %14.3f
		}
	}
	compress
	saveold "${root}\temp\trade_2002_2020_wide_`num'.dta", replace version(13)
	restore 
}


clear
foreach num of local sample {
	append using "${root}\temp\trade_2002_2020_wide_`num'.dta"
}

drop var_name

foreach var of varlist _all {
	label var `var' ""
}

sort SAMPLE land_id waren_art_id jahr woche  land_str
order SAMPLE jahr woche woche_seq53 woche_seq52 								///
land_id land_str land_iso2 land_region7 										///
waren_art_id waren_art_str														///
export_chf_mio export_chf_mia export_tonnen 									///
import_chf_mio import_chf_mia import_tonnen										///
datum_mo datum_di datum_mi datum_do datum_fr datum_sa datum_so 					///
land_EU land_EURO land_EEA waren_art_kat*										///
merge_land merge_waren merge_land_gruppen 
compress  

saveold "${root}\temp\trade_2002_2020_analysis_wide_temp.dta", replace version(13)

